package com.nanbei.a05;


import org.mybatis.spring.mapper.MapperFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.AnnotationBeanNameGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ConfigurationClassPostProcessor;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.MethodMetadata;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Objects;
import java.util.Set;

/**
 * @ClassDescription:  bean工厂后置处理器
 * @JdkVersion: 1.8
 * @Author: libs
 * @Created: 2024/11/13 14:38
 */
public class A05Application {
    public static void main(String[] args) throws IOException {
        // GenericApplicationContext 是一个【干净】的容器   内部未添加 bean工厂处理器 和 bean处理器
        GenericApplicationContext context = new GenericApplicationContext();
        context.registerBean("config", Config.class);
       /* context.registerBean(ConfigurationClassPostProcessor.class); // @ComponentScan  @Bean @Import @ImportResources
        context.registerBean(MapperScannerConfigurer.class,bd -> {
            bd.getPropertyValues().add("basePackage","com.nanbei.a05.mapper");
        }); //@MapperScanner*/

        // 模拟 bean工厂后处理器 进行 bean扫描
        // 判断 Config 类上是否有 @ComponentScan 注解

       // context.registerBean(ComponentScanPostProcessor.class); // 解析 @ComponentScan
        context.registerBean(AtBeanPostProcessor.class);  // 解析 @Bean
        context.registerBean(MapperPostProcessor.class);

        // 初始化容器
        context.refresh();
        for (String beanDefinitionName : context.getBeanDefinitionNames()) {
            System.out.println(beanDefinitionName);
        }

        // 销毁容器
        context.close();
    }
}
